<?php
class control extends kernel 
{
	protected $tpl;
	protected $user_id;
	protected $user_name;

	public function __construct() {
		parent::__construct();
		$this->_initControl();
	//	$this->_initTmp();
		$this->user_id = $this->load->session->get('user_id');
		$this->user_name = $this->load->session->get('user_name');
	}
	/**
	 * 加载基本的类 实例化
	 *
	 */
	private function _initControl() {
		$classes = config::$autoClass;
		foreach ($classes as $key=>$value) {
			$this->load->$key = $this->loadLib($value);
		}
	}
	
	protected function loadClass($data) {
		if(is_array($data)) {
			foreach($data as $key=>$value) {
				$this->load->$key = $this->loadLib($value);
			}
		}
	}
	
	/**
	 * 初始化smart模板，设置路径
	 *
	 * template_dir  模板存放路径
	 * compile_dir   编译路径
	 * cinfig_dir	 全局配置路径	
	 * cache_dir     缓存路径
	 */
	private function _initTmp() {
		if(BASEPATH.'lib/smarty/libs/Smarty.class.php') {
			require_once(BASEPATH.'lib/smarty/libs/Smarty.class.php');
			$this->tpl = new Smarty();
			$this->tpl->template_dir = BASEPATH.config::TEMPLATE_DIR ;
			$this->tpl->compile_dir = BASEPATH.config::COMPILE_DIR ;
			$this->tpl->config_dir = BASEPATH.config::CONFIG_DIR ;
			$this->tpl->cache_dir = BASEPATH.config::CACHE_DIR ;
		}
	}
	/**
	 * 输出xml头部信息，清除前面的缓存
	 *
	 */
	protected function xmlHeader() { 
		if( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
			header("Content-type: application/xhtml+xml"); 
		} else {
  			header("Content-type: text/xml");
		}
		ob_clean();
	}
	/**
	 * 判断是否登录
	 * 
	 */
	protected function isLogin() {
		if(is_numeric($this->user_id)) {
			return true;
		} else {
			$this->load->uri->redirect('login');
		}
	}	
	/**
	 *  不同的文件类型对应不同的应用程序
	 * 
	 */
	protected function getApp($ext) {
		if (in_array($ext,config::$image_app)) {
			return $app_name = 'image';
		}
	}
}
?>